﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using TRPOP.CMS.Web.UI;

using TRPOP.CMS.Business;
using TRPOP.CMS.Model;
using System.Data;
using TRPOP.Common;
namespace TRPOP.CMS.Web.Admin
{
    /// <summary>
    /// 获取左侧菜单列表
    /// </summary>
    public partial class GetFileTree : BaseAdmin
    {
        /// <summary>
        /// ref 表示左键点击跳转的页面 或 文件夹的响应name
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Page_Load(object sender, EventArgs e)
        {
            Response.ClearContent();
            Response.Expires = -1;
            Response.ExpiresAbsolute = DateTime.Now.AddSeconds(-1);
            Response.CacheControl = "no-cache";
            string strName = RequestHelper.RequestString("name");
            //strName = strName == "" ? "system" : strName;
            Response.Write("<ul class=\"jqueryFileTree\" style=\"display: none;\">\n");
            switch (strName)
            {
                case "system":
                case "node":
                case "publish":
                    DataTable dt = TRPOP.CMS.Plugin.Config.MenuConfig.GetLeftMenuByHeadName(strName);
                    foreach (DataRow dr in dt.Rows)
                    {
                        Response.Write("\t<li  class=\"" + dr["menuclass"] + "\"><a name=\"" + dr["menuname"] + "\" menu=\"" + dr["menu"] + "\" postname=\"" + dr["postname"] + "\"  href=\"" + dr["link"] + "\"  target=\"" + dr["frameid"] + "\" >" + dr["menutitle"] + "</a></li>\n");
                    }                   
                    break;
                case "system_Param":
                    ParamTypeManage oParamTypeManage = new ParamTypeManage();
                    foreach (ParamTypeInfo otempInfo in oParamTypeManage.GetListByCondition(0, "", " ParamTypeId " ) )
                    {
                        Response.Write("\t<li class=\"file\"><a name=\"system_ParamType\"   menu=\"true\" href=\"Param/Param_list.aspx?cid=" + otempInfo.ParamTypeId.ToString() + "\"  target=\"right\" param=\"&cid=" + otempInfo.ParamTypeId.ToString() + "\" > " + otempInfo.Name + "</a></li>\n");
                    }
                    break;
                case "system_PSN":
                    PSNManage oPSNManage = new PSNManage();
                    foreach (PSNInfo otempInfo in oPSNManage.GetListByCondition(0, "", "psnid"))
                    {
                        Response.Write("\t<li class=\"file\"><a  href=\"Param/PSN_Save.aspx?id=" + otempInfo.psnid.ToString() + "\"  target=\"right\" >" + otempInfo.Name + "</a></li>\n");
                    }
                    break;
                case "model":
                    Response.Write("\t<li  class=\"directory collapsed\"><a name=\"model\" menu=\"true\"   postname=\"model_list\"  href=\"model/model_list.aspx\"  target=\"right\">模型管理</a></li>\n");
                    break;
                case "model_list":
                    ModelManage oModelManage = new ModelManage();
                    foreach (ModelInfo oModelInfo in oModelManage.GetListByCondition(0, "", " ModelId asc "))
                    {
                        Response.Write("\t<li  class=\"file\"><a  href=\"model/model_save.aspx?id=" + oModelInfo.ModelId.ToString() + "\"  target=\"right\" rel=\"model/model_save.aspx?id=" + oModelInfo.ModelId.ToString() + "\">" + oModelInfo.Name + "</a></li>\n");
                    }
                    break;
                
                case "node_list":
                    NodeManage oNodeManage = new NodeManage();
                    int m_pid = RequestHelper.RequestInt("pid",0);
                    foreach (NodeInfo oNodeInfo in oNodeManage.GetListByCondition(0, " and  ParentId=" + m_pid, "   DisplayOrder asc "))
                    {
                        Response.Write("\t<li  class=\"directory collapsed\"><a name=\"node_children\"  postname=\"node_list\" menu=\"true\" nodeid=\"" + oNodeInfo.NodeId + "\" param=\"&pid=" + oNodeInfo.NodeId + "\"  href=\"node/node_save.aspx?id=" + oNodeInfo.NodeId.ToString() + "\"  target=\"right\" >" + oNodeInfo.Name + "</a></li>\n");
                    }
                    break;
                case "pubnode_list":
                     oNodeManage = new NodeManage();
                     m_pid = RequestHelper.RequestInt("nid", 0);
                    foreach (NodeInfo oNodeInfo in oNodeManage.GetListByCondition(0, " and  ParentId=" + m_pid, "   DisplayOrder asc "))
                    {
                        Response.Write("\t<li  class=\"directory collapsed\"><a name=\"pubnode_children\"  postname=\"pubnode_list\" menu=\"true\" nodeid=\"" + oNodeInfo.NodeId + "\" param=\"&nid=" + oNodeInfo.NodeId + "\"  href=\"publish/content_list.aspx?nid=" + oNodeInfo.NodeId.ToString() + "\"  target=\"right\" >" + oNodeInfo.Name + "</a></li>\n");
                    }
                    break;
                default :
                    break;
            }
            Response.Write("</ul>");            
        }
    }
}
